<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
include "ddbb.class.php";

class post_upload extends ddbb{

    private $host="db491742355.db.1and1.com";
    private $db="db491742355";
    private $user="dbo491742355";
    private $pass="1234qwerty";
    private $base_url="http://r-systems.es/_tests/uploadify/";


    public function __construct() {
        parent::__construct($this->host, $this->db, $this->user, $this->pass);
    }
      
    public function inserta_imagenes(){
        $sql="INSERT INTO imagenes (id,nombre,imagen) VALUES ";
        $arr_imagenes=$this->imagenes_string2array($_POST['nombre_imagen']);
        foreach($arr_imagenes as $imagen){
            $sql.="('','".$_POST['nombre']."','".$imagen."'),";
        }
        $sql=  substr($sql, 0,  strlen($sql)-1);
        return mysqli_query($this->con,$sql);
    }
    
    public function printa_imagenes(){ 
        $output="<u>id - nombre - imagen</u><br /><br />";
        $arr_imagenes=  $this->lee_imagenes();
        foreach ($arr_imagenes as $imagen){
            $output.=$imagen['id']." - ".$imagen['nombre']." - <a href='".$this->base_url."uploads/".$imagen['imagen']."' target='_blank'>".$imagen['imagen']."</a><br />";
        }
        return $output;
    }
    
    private function lee_imagenes(){
        $sql="SELECT * FROM imagenes";
        $res=mysqli_query($this->con, $sql);
        while($row=  mysqli_fetch_assoc($res)){
            $arr[]=$row;
        }
        return $arr;
    }
    
    private function imagenes_string2array($string){
        $arr=  explode(";", $string);
        unset($arr[sizeof($arr)-1]);
        return $arr;
    }
    public function __destruct() {
        $this->desconectar();
    }
    
}
?>
